🧾 Project Sardine System Architecture Overview
This document provides a high-level overview of the architecture of Project Sardine, its interaction with external services (like Project Jupiter), core components such as printing, bill processing, MediatR usage, Server-Sent Events (SSE) for monitoring, and financial account creation.
📦 Project Structure and Responsibilities
Project Sardine is a modular backend system responsible for:
- Checkout, bill generation, and printing
- Real-time monitor updates using SSE
- Financial journal integration for bills
- User account creation and financial linkage
It interacts with services like:
- Project Jupiter (External Print Service)
- Project Legolas (Financial accounts, journals, transactions)
🖨️ Print Flow via Project Jupiter
The PrintCustomerReceiptEndpoint in Checkout.BillPrint.Create is responsible for printing customer receipts:
-
Request is made to
/checkout/bill/print/customer-receipt. -
The endpoint retrieves receipt data from
ReceiptGeneratorHelper. -
A
ReceiptDocumentis created, potentially including a logo. -
It fetches the configured printer using
IPrinterService. -
Sends the document to Project Jupiter, which is responsible for actual printing of:
- 🧾 Customer receipts
- 👨🍳 Kitchen receipts
Project Jupiter is an external microservice that handles printing. It receives print jobs through REST requests from Project Sardine.
🧠 MediatR for Event Broadcasting
Project Sardine uses MediatR to publish domain events and handle them asynchronously. For example:
public class BillFinanceProcessor : INotificationHandler<BroadcastEventNotification<BillResponse>>
The BillFinanceProcessor reacts to BroadcastEventNotification<BillResponse> when:
- A bill is finished (
OrderFinished) - It handles Safari (delivery) and non-safari bills
- Starts a financial transaction process via
Project Legolas
📡 Real-Time Monitor Updates with SSE
SSE (Server-Sent Events) is used for real-time updates to the monitor screen.
Flow:
- A bill is modified (e.g., created, updated, printed).
- An event is broadcasted using MediatR.
- The SSE service listens and publishes the event to connected frontend clients.
- The UI updates in real-time without polling.
Events are queued internally to ensure delivery even during high load.
🧾 Financial Account Creation
When a user, customer, or delivery driver is created in the system:
- A financial account is automatically created via the
AccountsService. - This ensures that every actor is financially linked in the journal system.
Account types include:
| Entity | Account Use |
|---|---|
User | Cash transaction recording |
Customer | Track sales & debts |
DeliveryDriver | Track safari bill assignments |
💸 Bill Financial Processing (Project Legolas Integration)
Component: BillFinanceProcessor
Trigger:
- Listens to bill completion events (e.g.,
OrderFinished,SafariOrderFinished)
Flow:
-
Deserializes the event to
BillResponse. -
Determines the correct account:
- For Safari → Delivery Driver
- Otherwise → Customer
-
Begins a DB transaction.
-
Creates a
SaleTransactionRequest:- Includes Revenue, Discounts, and Paid amounts
-
Converts request →
SaleTransactionand appends it to journal in Project Legolas -
Commits the transaction.
-
Associates the transaction to the bill.
Transactions are handled safely and ensure data consistency with rollback support.
⚙️ Tech Stack and Libraries
| Feature | Library/Tool |
|---|---|
| API Routing | FastEndpoints |
| Event Mediation | MediatR |
| Real-Time Communication | Server-Sent Events (SSE) |
| Database ORM | EF Core |
| Financial Ledger | Project Legolas |
| External Print Service | Project Jupiter |
| Pdf document generator | QuestPDF |
🧮 Constants and Settings
- Printer Name is configured via
AppSettings.InvoiceSettings.PrinterName - Logo Image for receipts is loaded from uploaded files based on settings
- Business ID and chart of accounts are managed via
Consts.BusinessId
📌 Summary
Project Sardine is a service-oriented backend system that handles:
- Checkout and billing logic
- Delegates printing to a dedicated external print microservice
- Broadcasts events using
MediatRand SSE - Ensures that each user or customer has a tied financial account
- Processes journal transactions using Project Legolas
This architecture makes the system modular, real-time, and financially accountable, supporting extensibility and scalability in a production-grade environment.